<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Use correct character set. -->
    <meta charset="utf-8">
    <!-- Tell IE to use the latest, best version. -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Hello World!</title>
    <script src="../Build/Cesium/Cesium.js"></script>
    <style>
        @import url(../Build/Cesium/Widgets/widgets.css);
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="credit"></div>
        <div id="cesiumContainer">
        <div id="cesiumxin" style="position:fixed;left:0;z-index:99"><a href="http://cesium.xin" style="color:aliceblue;text-decoration:none">cesium中文网 http://cesium.xin </a></div>
    </div>
    <script>
        var viewer = new Cesium.Viewer('cesiumContainer', {
            //2.本地图片
            imageryProvider: new Cesium.SingleTileImageryProvider({
                url: '../img/worldimage.jpg'
            }),
            //geocoder: false,
            homeButton: false,
            sceneModePicker: false,
            baseLayerPicker: false,
            navigationHelpButton: false,
            animation: false,
            creditContainer: "credit",
            timeline: false,
            fullscreenButton: false,
            vrButton: false
        });

        //地形
        /*
        var viewer = new Cesium.Viewer('cesiumContainer',{
            imageryProvider: new Cesium.SingleTileImageryProvider({
                url: '../img/worldimage.jpg'
            }),
        });
        // 添加地形
        var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
            url: 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
            requestVertexNormals: true
        });
        viewer.terrainProvider = cesiumTerrainProviderMeshes;
        */

        //camera position {x: -2277788.735618622, y: 5411552.618440122, z: 2483810.1472630273}

        //普通线
        // var yellowLine = viewer.entities.add({
        //     name: 'Red line on the surface',
        //     corridor: {
        //         positions: Cesium.Cartesian3.fromDegreesArray([
        //             112.82436,
        //             23.071506,
        //             112.82742,
        //             23.067512,
        //             112.828878,
        //             23.064659,
        //             112.830799,
        //             23.060947,
        //             112.832166,
        //             24.058329
        //         ]),
        //         width: 2,
        //         material: Cesium.Color.YELLOW
        //     }
        // });

        //第一种
        // var redCorridor = viewer.entities.add({
        //     name: 'Red corridor on surface with rounded corners',
        //     corridor: {
        //         positions: Cesium.Cartesian3.fromDegreesArray([
        //             112.82436,
        //             23.071506,
        //             112.82742,
        //             23.067512,
        //             112.828878,
        //             23.064659,
        //             112.830799,
        //             23.060947,
        //             112.832166,
        //             23.058329
        //         ]),
        //         width: 20.0,
        //         material: Cesium.Color.YELLOW
        //     }
        // });


        //第二种 线
        // viewer.dataSources.add(Cesium.GeoJsonDataSource.load('http://localhost:1234/lesson07/pwt1/line.json', {
        //     clampToGround: true
        // }));

        // var cartographics = [new Cesium.Cartographic(112.82536, 23.071506),
        //     new Cesium.Cartographic(112.832166, 23.058329),
        //     new Cesium.Cartographic(112.833166, 23.059329),
        //     new Cesium.Cartographic(112.82636, 23.072506)
        // ];
        // var rectangle = Cesium.Rectangle.fromCartographicArray(cartographics);

        var rectanglePrimitive = viewer.scene.primitives.add(new Cesium.GroundPrimitive({
            geometryInstances: new Cesium.GeometryInstance({
                geometry: new Cesium.CorridorGeometry({
                    vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
                    positions: Cesium.Cartesian3.fromDegreesArray([112.82536, 23.071506, 112.82742, 23.067512, 112.828878, 23.064659, 112.830799, 23.060947, 112.832166, 23.058329]),
                    width: 40
                }),
                attributes: {
                    color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 1.0, 0.0, 0.5))
                }
            }),
            /*
            // 添加地形
            classificationType: Cesium.ClassificationType.TERRAIN
            */
        }));


        //点云

        var url2 = 'pwt1/pts/tileset.json';
        var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
            url: url2
                //url : 'https://beta.cesium.com/api/assets/1460?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMzk2YzJiOS1jZGFmLTRlZmYtYmQ4MS00NTA3NjEwMzViZTkiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjBdLCJpYXQiOjE0OTkyNjQ3NTV9.oWjvN52CRQ-dk3xtvD4e8ZnOHZhoWSpJLlw115mbQJM'
        }));

        var style = {
            color: "color('#ff0000')"
        };
        style.pointSize = Cesium.defaultValue(style.pointSize, 5.0);
        tileset.style = new Cesium.Cesium3DTileStyle(style);


        viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(112.82536, 23.071506, 500.0),
            orientation: {
                heading: Cesium.Math.toRadians(145.0),
                pitch: Cesium.Math.toRadians(-35.0),
                roll: 0.0
            }
        });

        // var entity = viewer.entities.add({
        //     position: Cesium.Cartesian3.fromDegrees(112.82536, 23.071506, 100),
        //     ellipse: {
        //         semiMinorAxis: 300.0,
        //         semiMajorAxis: 300.0,
        //         material: Cesium.Color.BLUE.withAlpha(1.0) //可设置不同的MaterialProperty
        //     }
        // });

        // viewer.entities.add({
        //     position: Cesium.Cartesian3.fromDegrees(112.82742, 23.067512, 200),
        //     ellipse: {
        //         semiMinorAxis: 300.0,
        //         semiMajorAxis: 300.0,
        //         material: Cesium.Color.AQUA.withAlpha(1.0) //可设置不同的MaterialProperty
        //     }
        // });
    </script>
</body>

</html>